﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FrameWork.Source.FrameWork;
using Microsoft.Xna.Framework;
using FrameWork.Source.Texture;
using FrameWork.Source.CMenu_class;
using FrameWork.Source.Resource_Manager;
using Microsoft.Xna.Framework.Input;
using FrameWork.Source.Screen;
using Boomer.Source.Boom;
using Boomer.Source.Breakable_Object;
using Boomer.Source.FrameWork.State_and_Screen_Manager.State.MainState.MainScreen;

namespace Boomer.Source.FrameWork.State_and_Screen_Manager.State
{
    class LoseState : IGameState
    {
        CTexture menuImage;
        CMenu menu;

        public LoseState(StateManager pState)
            : base(pState)
        {
            menu = null;
            menuImage = null;
        }


        public override void init()
        {
            menuImage = CResourceManager.getInstance().getImage((int)CResourceManager.IMG_MAIN.LOSEBG);

            CMenuItem pResume = new CMenuItem();
            pResume.createItem("Back to menu", null, 300, 70, new Vector2(243, 210), true);

            CMenuItem pBackToMenu = new CMenuItem();
            pBackToMenu.createItem("Replay", null, 250, 70, new Vector2(266, 307), true);

            menu = new CMenu();
            menu.addItem(pResume);
            menu.addItem(pBackToMenu);
            
            base.init();
        }

        public override void update(GameTime gameTime)
        {
            processInput();

            base.update(gameTime);
        }

        public override void render(GameTime gameTime)
        {
            m_pState.m_pSpriteHandler.Begin();

            menuImage.drawImage(new Vector2(0, 0), Color.White);

            m_pState.m_pSpriteHandler.End();

            base.render(gameTime);
        }

        public void processInput()
        {
            MouseState mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                CMenuItem pItem = null;
                menu.picking(mouse.X, mouse.Y, ref pItem);
                if (pItem != null)
                {
                    if (pItem.m_strName == "Replay")
                    {
                        m_pState.setNextState(new MainGameState(m_pState));
                        BoomManager.getInstance().clear();
                        ObjectManager.getInstance().clear();
                        Effect.EffectManager.getInstance().clear();
                        WaveManager.WaveManager.getInstance().reset();
                    }
                    if (pItem.m_strName == "Back to menu")
                    {
                        m_pState.setNextState(new MainMenuState(m_pState));
                        BoomManager.getInstance().clear();
                        ObjectManager.getInstance().clear();
                        Effect.EffectManager.getInstance().clear();
                        WaveManager.WaveManager.getInstance().reset();
                    }
                }
            }
        }

        public override void destroy()
        {
            base.destroy();
        }

        
    }
}
